# coding=utf-8

__author__ = 'linzh'

from flask import Flask, jsonify, session, request, make_response

app = Flask(__name__)
app.config['SECRET_KEY'] = 'hard to guess'

@app.route('/')
def index():
    return 'hello, world'


@app.route('/file-upload', methods=['GET', 'POST'])
def file_upload():
    """
    文件上传DEMO
    """
    return "test"


@app.route('/jsonify-test', methods=['GET', 'POST'])
def jsonify_test():
    data_rtn = {"age": 13}
    return jsonify(data_rtn)


@app.route('/jsonify-code')
def jsonify_code():
    response = jsonify({"age": 13})
    response.status_code = 404
    return response


@app.route('/session-test', methods=['GET', 'POST'])
def session_test():
    session['age'] = 13
    return make_response("session")


@app.route('/session-get')
def session_get():
    return make_response(str(session.get('age')))


@app.route('/cookie-test')
def cookie_test():
    response = make_response("test")
    response.set_cookie("age", '13')
    return response


@app.route('/cookie-get')
def cookie_get():
    return make_response(request.cookies.get('age'))

if __name__ == '__main__':
    app.run(port=5002, debug=True)

